package dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/** Donne une connexion à notre base de données */
public class FabriqueDAO {
	  // Nom du pilote (driver). Dans ce cas, MySQL
	  private static final String DRIVER_NAME = "com.mysql.jdbc.Driver";
	  private static final String DB_NAME = "agriotes";
	  private static final String URL = "jdbc:mysql://localhost/" + DB_NAME;
	  private static final String USER = "agriotes";
	  private static final String PASSWORD = "agriotes";
	  
	  static {
	    // Chargement du pilote
	    // N'aura lieu qu'une seule fois
	    try {
	    
	      Class.forName(DRIVER_NAME).newInstance();
	      //System.out.println("*** Driver loaded.");
	    }
	    catch (ClassNotFoundException e) {
	      System.err.println("*** ERROR: Driver " + DRIVER_NAME + " not found");
	    }
	    catch (InstantiationException e) {
	      System.err.println("*** ERROR: Impossible to create an instance of " + DRIVER_NAME);
	      System.err.println(e.getMessage());
	    }
	    catch (IllegalAccessException e) {
	      System.err.println("*** ERROR: Impossible to create an instance of " + DRIVER_NAME);
	      System.err.println(e.getMessage());
	    }
	  }
	  
	  public static Connection getConnection() throws SQLException {
		return DriverManager.getConnection(URL, USER, PASSWORD);
	  }
	  
}	  